package com.ushine.web.template.validation.model;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.ushine.web.component.validation.ToolInterface;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import org.springframework.data.annotation.CreatedBy;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.validation.constraints.*;

/**
 * @Author: yls
 * @Date 2022/2/11 11:29
 * @Description: 数据校验实体类
 * @Version 1.0
 **/
@Data
@Getter
@Setter
@Entity
@Table(name = "t_cp_validation")
@org.hibernate.annotations.Table(appliesTo = "t_cp_validation", comment = "数据校验实体表")
@TableName(value = "t_cp_validation")
@ApiModel(description = "数据校验实体表")
public class ValidationDO {
    /**
     * 编号
     * // 解决前台js接收雪花id精度丢失问题
     * <p>
     * JsonFormat(shape = JsonFormat.Shape.STRING)
     */
    @Id
    @CreatedBy
    @TableId(type = IdType.ASSIGN_ID)
    @ApiModelProperty("编号")
    @JsonFormat(shape = JsonFormat.Shape.STRING)
    @Column(name = "id", columnDefinition = "bigint comment '编号'")
    private Long id;

    /**
     * 用户名：分组校验
     */
    @ApiModelProperty("用户名")
    @NotNull(message = "用户名不能为空")
    @Size(groups = {ToolInterface.Insert.class, ToolInterface.Update.class}, min = 8, max = 12, message = "账号的长度必须为（8-12）")
    @Column(name = "username", columnDefinition = "varchar(32) NOT NULL unique comment '用户名'")
    private String username;

    /**
     * 年龄：分组校验，范围校验
     */
    @ApiModelProperty(value = "年龄", example = "0")
//    @Min(value = 1, message = "年龄范围必须在（1-200）")
//    @Max(value = 200, message = "年龄范围必须在（1-200）")
    @Column(name = "age", columnDefinition = "int comment '年龄'")
    private Integer age;

    /**
     * 地址
     */
    @ApiModelProperty("地址")
    @NotBlank(message = "地址不能为空")
    @Column(name = "address", columnDefinition = "varchar(255) comment '地址'")
    private String address;

    /**
     * 性别
     */
    @ApiModelProperty("性别")
    @NotBlank(message = "性别不能为空")
    @Column(name = "sex", columnDefinition = "varchar(8) comment '性别'")
    private String sex;

    /**
     * 邮箱 : 邮箱合法性校验 、 分组校验
     */
    @ApiModelProperty("邮箱")
    @NotBlank(groups = {ToolInterface.Insert.class, ToolInterface.Update.class}, message = "邮箱不能为空")
//    @Email(message = "邮箱地址不正确")
    @Column(name = "email", columnDefinition = "varchar(64) comment '邮箱'")
    private String email;


}
